package catalina.connection;

import catalina.startup.StandardService;

import java.io.InputStream;
import java.net.Socket;

public class RequestProcessor extends Thread {

    private Socket socket;
    private StandardService standardService;

    public RequestProcessor(Socket socket, StandardService standardService) {
        this.socket = socket;
        this.standardService = standardService;
    }

    @Override
    public void run() {
        try{
            InputStream inputStream = socket.getInputStream();
            // 封装Request对象和Response对象
            Request request = new Request(inputStream);
            Response response = new Response(socket.getOutputStream());
            this.standardService.getContainer().service(request,response);
            socket.close();
        }catch (Exception e) {
            e.printStackTrace();
        }

    }
}
